package leetcode.code0841;

import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

import leetcode.IDebug;

public class Solution implements IDebug {

	public boolean canVisitAllRooms(List<List<Integer>> rooms) {
		int n = rooms.size();
		boolean[] v = new boolean[n];
		Queue<Integer> queue = new LinkedList<>();
		queue.add(0);
		v[0] = true;
		n--;
		while (!queue.isEmpty()) {
			int id = queue.poll();
			List<Integer> nexts = rooms.get(id);
			for (int next : nexts) {
				if (!v[next]) {
					v[next] = true;
					n--;
					queue.add(next);
				}
			}
		}
		return n == 0;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
